﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    class BooFivePointed : BooTextShapesBase
    {
        Shapes.Polygon fivePointed;
        public Shapes.Polygon FivePointed
        {
            get { return fivePointed; }
            set { fivePointed = value; }
        }

        BooFivePointedElement fivePointedElement;
        public BooFivePointedElement FivePointedElement
        {
            get { return fivePointedElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return fivePointedElement; }
        }

        public override BooElement Element
        {
            set { fivePointedElement = (BooFivePointedElement)value; }
            get { return fivePointedElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return fivePointed; }
        }

        public BooFivePointed(BooFivePointedElement element, SaveForRedoUndo saveForRedoUndo)
            : base(element)
        {
            this.fivePointedElement = element;
            InitOriginal();
            base.saveForRedoUndo = saveForRedoUndo;
            Focus.InitFocusEvent(this);
        }

        public BooFivePointed(BooFivePointedElement element)
            : base(element)
        {
            this.fivePointedElement = element;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            fivePointed = new Shapes.Polygon();
            fivePointed.Points = BooShapesPoints.CopyPointCollection(this.fivePointedElement.Points);
            fivePointed.ManipulationMode = ManipulationModes.All;
        }

        public override void ReSizeUI(double x, double y)
        {
            if (fivePointedElement.ElementTransform.Width + x < 50 || fivePointedElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            fivePointedElement.ElementTransform.Width = fivePointedElement.ElementTransform.Width + x;
            fivePointedElement.ElementTransform.Height = fivePointedElement.ElementTransform.Height + y;
            fivePointedElement.PropertyChanged("Shape");
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }



        public override void ApplySize()
        {
            base.ApplySize();
            fivePointedElement.ShapeWidth = fivePointedElement.ElementTransform.Width;
            fivePointedElement.ShapeHeight = fivePointedElement.ElementTransform.Height;

            //this.fivePointed.Width = fivePointedElement.ElementTransform.Width;
            //this.fivePointed.Height = fivePointedElement.ElementTransform.Height;

            FullGrid.Width = fivePointedElement.ElementTransform.Width;
            FullGrid.Height = fivePointedElement.ElementTransform.Height;

            //BooCanvas.Width = fivePointedElement.ElementTransform.Width;
            //BooCanvas.Height = fivePointedElement.ElementTransform.Height;

            CenterStack.Width = fivePointedElement.ElementTransform.Width;
            //CenterStack.MaxHeight = fivePointedElement.ElementTransform.Height;


            this.TextBox.Width = fivePointedElement.ElementTransform.Width;
            fivePointedElement.TextWidth = fivePointedElement.ElementTransform.Width;
            //this.TextBox.MaxHeight = fivePointedElement.ElementTransform.Height;
            //fivePointedElement.TextMaxHeight = fivePointedElement.ElementTransform.Height;


            Focus.FocusElls.ScopeRectangle.Width = fivePointedElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = fivePointedElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(fivePointedElement.ElementTransform.Width, fivePointedElement.ElementTransform.Height);

            Point[] pt = new Point[fivePointedElement.Points.Count];
            PointCollection pts = new PointCollection();
            fivePointedElement.Points.CopyTo(pt, 0);
            pt[0].X = fivePointedElement.ElementTransform.Width * 0.5;
            pt[0].Y = 0;
            pt[1].X = fivePointedElement.ElementTransform.Width * 0.6;
            pt[1].Y = fivePointedElement.ElementTransform.Height * 0.4;
            pt[2].X = fivePointedElement.ElementTransform.Width;
            pt[2].Y = fivePointedElement.ElementTransform.Height * 0.4;
            pt[3].X = fivePointedElement.ElementTransform.Width * 0.65;
            pt[3].Y = fivePointedElement.ElementTransform.Height * 0.6;
            pt[4].X = fivePointedElement.ElementTransform.Width * 0.8;
            pt[4].Y = fivePointedElement.ElementTransform.Height;
            pt[5].X = fivePointedElement.ElementTransform.Width * 0.5;
            pt[5].Y = fivePointedElement.ElementTransform.Height * 0.7;
            pt[6].X = fivePointedElement.ElementTransform.Width * 0.2;
            pt[6].Y = fivePointedElement.ElementTransform.Height;
            pt[7].X = fivePointedElement.ElementTransform.Width * 0.35;
            pt[7].Y = fivePointedElement.ElementTransform.Height * 0.6;
            pt[8].X = 0;
            pt[8].Y = fivePointedElement.ElementTransform.Height * 0.4;
            pt[9].X = fivePointedElement.ElementTransform.Width * 0.4;
            pt[9].Y = fivePointedElement.ElementTransform.Height * 0.4;
            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            pts.Add(pt[3]);
            pts.Add(pt[4]);
            pts.Add(pt[5]);
            pts.Add(pt[6]);
            pts.Add(pt[7]);
            pts.Add(pt[8]);
            pts.Add(pt[9]);
            fivePointed.Points = pts;
            fivePointedElement.Points = pts;
        }
    }
}
